import { load } from '/views/admin/admin.js'
load('create')

let photo = ''
createform.onsubmit = async function (e) {
  e.preventDefault()

  // console.log(photo)
  await fetch('http://localhost:3000/users', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      username: username.value,
      password: password.value,
      userintro: userintro.value,
      photo
    })
  }).then((res) => res.json())

  location.href = '/views/admin/user/list/index.html'
}
photofile.onchange = function (evt) {
  let reader = new FileReader()
  reader.readAsDataURL(evt.target.files[0])
  reader.onload = function (e) {
    photo = e.target.result
  }
}
